using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls; 

namespace IGlobalist.Cms.Common
{
    public class AdminBasePage: Page
    {

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!IGlobalistMembership.IsAuthenticate) Response.Redirect("Login.aspx");
            
        }

        protected override void OnInit(EventArgs e)
        {
            if (!SecurityManager.IsHasPermission())
            {
                string urlReturn = Request.Url.PathAndQuery;
                urlReturn = urlReturn.Substring(urlReturn.IndexOf("/"));
                string page = ConfigurationManager.AppSettings.Get("URLPermissionDenied");
                Response.Redirect(string.Format("{0}?urlReturn={1}" ,page, urlReturn));
            }
            base.OnInit(e);

        }


        public log4net.ILog Logger
        {
            get { return log4net.LogManager.GetLogger("File"); }
        }
        public void TestLog()
        {
            Logger.Error("This is an error", new Exception("xfdfdfd"));            
        }


        public string DataRootVirtualPath
        {
            get
            {
                return ConfigurationSettings.AppSettings.Get("RootDataFolder");
            }
        }
        public string DataRootPhysicalPath
        {
            get
            {
                string path = HttpContext.Current.Server.MapPath(DataRootVirtualPath);
                if (!System.IO.Directory.Exists(path))
                    System.IO.Directory.CreateDirectory(path);
                return path;
            }
        }

        public string FolderUploadVirtualPath
        {
            get
            {
                return DataRootVirtualPath + "/FileUpload";
            }
        }
        public string FolderUploadPhysicalPath
        {
            get
            {
                string path = HttpContext.Current.Server.MapPath(FolderUploadVirtualPath);
                if (!System.IO.Directory.Exists(path))
                    System.IO.Directory.CreateDirectory(path);
                return path;
            }
        }
    }
}
